//
//  MQBaseTabBarViewController.m
//  meiquan
//
//  Created by hejingjin on 2017/10/21.
//  Copyright © 2017年 mq. All rights reserved.
//

#import "MQBaseTabBarViewController.h"
#import "MQNavigationViewController.h"

#import "CustomsViewController.h"
#import "StoreViewController.h"
#import "HomeViewController.h"
#import "MineViewController.h"
@interface MQBaseTabBarViewController ()

@end

@implementation MQBaseTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    //1.首页
    [self setupChildVc:[[HomeViewController alloc] init] title:@"首页" image:@"home_01" selectedImage:@"home"];
    
    
    [self setupChildVc:[[StoreViewController alloc] init] title:@"商城" image:@"mall_01" selectedImage:@"mall"];
    
    [self setupChildVc:[[CustomsViewController alloc] init] title:@"客服" image:@"help_01" selectedImage:@"help"];
    
    [self setupChildVc:[[MineViewController alloc] init] title:@"个人中心" image:@"user_01" selectedImage:@"user"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


+ (void)initialize
{
    
//    DSCQCustomFont *customfont = [DSCQCustomFont shareInstance];
    // 通过appearance统一设置所有UITabBarItem的文字属性
    // 后面带有UI_APPEARANCE_SELECTOR的方法, 都可以通过appearance对象来统一设置
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:11]; //未选中字体
    attrs[NSForegroundColorAttributeName] = BSTColorFromRGB(0x838383);  //未选中颜色
    
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];    //选中字体
    selectedAttrs[NSForegroundColorAttributeName] = BSTColorFromRGB(0xff8e01); //选中颜色
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
}



 /**
 * 初始化tabbar子控制器
 */

- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 设置文字和图片
    vc.navigationItem.title = title;
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    
    // 包装一个导航控制器, 添加导航控制器为tabbarcontroller的子控制器
    MQNavigationViewController  *nav = [[MQNavigationViewController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
    
}

@end
